import BuffUtil from '@/BuffUtil';
import UnitStateUtil from '@/UnitStateUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 不动明王
 **/
export default class WS_StableKing extends AbilityBase {
    static instance: WS_StableKing;
    buffType: AppBuffType = {
        id: 'buff_WS_StableKing',
        art: this.art,
        name: this.abilityName,
        ubertip: '将受到的伤害反伤，且回复生命和魔法',
        dur: 2,
        targetAttach: 'origin',
        targetArt: 'Abilities\\Spells\\Undead\\Unsummon\\UnsummonTarget.mdl',
    };
    constructor(id: string = 'Abdw') {
        super(id);
        WS_StableKing.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
        EventManager.onTakeDamage(this.onDamageEffect.bind(this));
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        // BuffUtil.addBuff(source, this.buffType.id, source);
        BuffCommon.addBuff({ target: source, caster: source, buffTypeId: this.buffType.id, ablityId: this.id });
        StunSystemIntance.stun(source, 2, source);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    onDamageEffect(d: DamageEventData) {
        if (!BuffUtil.hasUnitBuff(d.target, this.buffType.id)) return;
        let dmg = d.lastDamage;
        DamageSystemInstance.applyHeal(d.target, d.target, dmg, this.id);
        UnitStateUtil.addMana(d.target, dmg);
        DamageSystemInstance.applyReflectDamage(d.source, d.target, dmg * 0.5 * this.getAbilityLevel(d.source), this.id);
        DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\NightElf\\ThornsAura\\ThornsAuraDamage.mdl', d.source, 'overhead'));
        d.lastDamage = 0;
    }
}
